package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceContainerLogEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年2月16日 下午2:04:16
*@author wenwenlong
*类说明
*/
@Implements(FinanceContainerLogService.class)
public class FinanceContainerLogServiceImpl implements FinanceContainerLogService{

	@Override
	@Transactional
	public Long createFinanceContainerLog(FinanceContainerLogEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getContainerLogId();
	}

	@Override
	@Transactional
	public void updateFinanceContainerLog(FinanceContainerLogEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public List<FinanceContainerLogEntity> inquireFinanceContainerLogList(Long inventoryId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceContainerLogEntity.class);
		criteria.add(Restrictions.eq("inventoryId", inventoryId));
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<FinanceContainerLogEntity> inquireFinanceContainerLogPageList(Long inventoryId, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceContainerLogEntity.class);
		criteria.add(Restrictions.eq("inventoryId", inventoryId));
		return PersistUtil.get(criteria, page);
	}
}
